<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title>设置默认路径</title>

    <link rel="stylesheet" href="../css/mui.min.css" />
    <!--App自定义的css-->
    <link rel="stylesheet" type="text/css" href="../css/app.css" />
    <link rel="stylesheet" href="../npl/css/vant.mini.css" />
    <script src="../js/sourtable.js"></script>
    <script src="../js/vuedraggable.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../js/flexible.js"></script>

    <script src="../js/vconsole.min.js"></script>
    <script src="../js/mui.min.js"></script>
    <script src="../js/jquery-3.6.0.min.js"></script>
    <script src="../js/sm2.js"></script>
    <script src="../js/sm3.js"></script>
    <script src="../npl/js/vant.mini.js"></script>
    <script src="./text.js" type="text/javascript"></script>
    <style>
        html,
        body,
        #app {
            overflow: hidden;
        }

        img {
            pointer-events: none !important;
        }

        .box .header_tit .van-nav-bar {
            background-color: initial;
        }

        .box {
            display: flex;
            height: 100%;
            width: 100%;
            overflow: hidden;
            flex-direction: column;
        }

        ::-webkit-scrollbar {
            /* 滚动条整体宽度/高度（垂直滚动条为宽度，水平滚动条为高度） */
            width: 1px;
            /* 垂直滚动条宽度 */
        }

        .defPath {
            height: 100%;
            width: 100%;
            padding: 0 20px;
            /* border: 1px solid red; */
        }

        .path_box {
            width: 100%;
            display: flex;
            height: 1.5rem;

            justify-content: space-between;
            align-items: center;
            border-top: 1px solid #eaeefb;
            border-bottom: 1px solid #eaeefb;

        }

        .path_l {
            display: flex;
            width: 90%;
            align-items: center;
        }

        .path_img {
            width: .8rem;
            height: .8rem;
        }

        .path_img img {
            width: 100%;
            height: 100%;
        }

        .path_text_red {
            color: red;
            font-size: 12px;

        }

        .path_text {
            color: black;
            margin: 0 5px 0 10px;
            font-size: 15px;
        }

        .path_r {
            position: relative;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .van-popover__action {
            width: 5.3rem;
        }

        .van-popover__action-text {
            font-size: 12px;
        }

        .van-icon-info-o:before {
            font-size: 12px;
            color: orange;
        }

        .van-popover {
            font-size: 12px;
            position: absolute;
            left: 2rem !important;
            top: 2.1rem !important;
        }

        .path_list {
            display: flex;
            justify-content: space-between;
            /* height: 1.5rem; */
            border-bottom: 1px solid #eaeefb;
        }

        .pathList_img {
            width: .8rem;
            height: .8rem;
        }

        .pathList_img img {
            width: 100%;
            height: 100%;
        }

        .list_box {
            display: flex;
            width: 80%;
            align-items: center;

        }

        .list_text {
            color: black;
            width: 75%;
            /* flex: 1; */
            word-wrap: break-word; 
            word-break: normal;
            margin: 0 5px 0 10px;
            font-size: 15px;
        }

        .liat_Btn {
            width: 20%;
            display: flex;
            align-items: center;
            justify-content: space-around;
        }

        .liat_Btn div {
            width: 15px;
            height: 15px;
        }

        .liat_Btn div img {
            width: 100%;
            height: 100%;
        }

        .form_btn {
            width: 100%;
            display: flex;
            padding: 0 5%;
            justify-content: space-between;
        }

        .form_btn .qx {
            width: 47%;
            background-color: rgba(45, 52, 60, 0.08);
            border-radius: 48px;
            font-family: PingFang SC;
            color: rgba(45, 52, 60, 0.8);
        }

        .form_btn .tj {
            width: 47%;
            background-color: #5f84f7;
            color: #fff;
            border-radius: 48px;
        }

        .van-popup--center {
            border-radius: 12px;
            width: 90%;
            padding: 20px 10px;
            display: flex;
            justify-content: space-around;
            flex-direction: column;
            height: 50%;
        }

        .NamePop .van-popup--center {
            border-radius: 12px;
            width: 80%;
            padding: 20px 10px 10px;
            display: flex;
            justify-content: space-around;
            flex-direction: column;
            height: 25%;
        }
    </style>
</head>

<body>
    <div class="box" v-cloak>
        <div class="header_tit">
            <van-nav-bar title="默认路径" left-arrow>
                <template #left>
                    <div class="back_l" @click="home"><img src="../image/left.png" alt=""></div>
                </template>
            </van-nav-bar>
        </div>
        <!-- 显示重命名弹框 -->
        <div class="NamePop">
            <van-popup style="min-height: 4rem;" :close-on-click-overlay="false" v-model="showPopName">
                <van-form>
                    <div style="text-align: center;font-size: 18px;font-weight:bold;margin-bottom: 10px;">重命名</div>
                    <van-field v-model="inputText" class="edit_title_input" placeholder="请输入文件名称" maxlength="100" />
                </van-form>
                <div class="form_btn">
                    <van-button type="default" style="width: 45%;" round @click="showPopName=false">取消</van-button>
                    <van-button type="primary" style="width: 45%;" color="#13C09B" round @click="operaFilePath('1')">确定
                    </van-button>
                </div>
            </van-popup>
        </div>
        <div class="defPath">
            <div class="path_box" >

                <div class="path_l" @click="selectFolder">
                    <div class="path_img"><img src="../image/path.png" alt=""></div>
                    <div class="path_text">添加默认路径</div>
                    <div class="path_text_red">(最多添加五个)</div>
                </div>
                <div style="width: 10%;height: 100%;" class="path_r">
                    <van-popover class="path_pop" style="left:0px;right: 10px;top: 0px;" width="550"
                        placement="bottom-end" theme="dark" v-model="showPopover" trigger="click" :actions="actions">
                        <template #reference>
                            <van-icon slot="reference" name="info-o" />
                        </template>
                    </van-popover>
                </div>
            </div>
            <div class="path_list" v-for="item in filePathList">
                <div class="list_box">
                    <div class="pathList_img">
                        <img src="../image/pathImg.png" alt="">
                    </div>
                    <div class="list_text">{{item.pathName}}</div>

                </div>
                <div class="liat_Btn">
                    <div @click="rename(item)">

                        <img src="../image/bj1.png" alt="">
                    </div>
                    <div @click="operaFilePath('2',item.id)">
                        <img src="../image/del2.png" alt="">
                    </div>
                </div>
            </div>

        </div>
    </div>
</body>

<script>
    new Vue({
        el: ".box",
        data() {
            return {
                actions: [{
                    text: '请升级到i国网3.1.3版本及以上使用该功能'
                }],
                showPopName: false,
                renameId: '',
                inputText: '',
                showPopover: false,
                filePathList: [],
            };
        },
        components: {
            draggable: vuedraggable

        },
        created() {
            const _this = this
            let jsApiList = []
            $.getScript("../js/jweixin-sgccigw-1.0.0.js" /*"js/jweixin-1.0.0.js"*/ , function () {
                'use strict';
                wx.ready(function () {
                    wx.onHistoryBack(() => {
                        _this.home()
                        return false
                    })
                });
                jsApiList = [
                    'onHistoryBack',
                    'ext_FileBrowser_ChooseDir',
                    'ext_FileBrowser_AppointDirChooseFile'
                ];
                wx.config({
                    beta: true, // 调用wx.invoke形式的接口值时，该值必须为true。
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: corpid, // 必填，政务微信的cropID
                    timestamp: '1626832073', // 必填，生成签名的时间戳
                    nonceStr: nonceStr, // 必填，生成签名的随机串
                    signature: signature, // 必填，签名，见附录1
                    jsApiList: jsApiList // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
                });
            });
        },
        mounted() {
            this.getList()
        },
        methods: {
            rename(item) {
                this.renameId = item.id
                this.inputText = item.pathName
                this.showPopName = true
            },

            selectFolder() {
                if (this.filePathList.length >= 5) {
                    mui.toast('最多添加五个默认路径', {
                        duration: '1000',
                        type: 'div'
                    })
                    return
                }

                wx.invoke("ext_FileBrowser_ChooseDir", {}, (res) => {
                    console.log("ext_FileBrowser_ChooseDir end", res);
                    var pathName
                    if(res.result) {
                       pathName = JSON.parse(res.result).path ? JSON.parse(res.result).path : ''
                    }
                    
                    console.log(pathName,"路径")
                    if(!pathName){
                        mui.toast('请选择路径', {
                            duration: '1000',
                            type: 'div'
                        })
                        return
                    }
                    // console.log()
                    // var pathName = this.getStringAfterLastColon(decodeURIComponent(res.result.replace(
                    //     "file://", "")))
                    this.saveFilePath(res.result, pathName) //保存接口
                })
            },
            // 保存路径接口
            saveFilePath(val, name) {
                const userId = sessionStorage.getItem("userId");
                const orgId = sessionStorage.getItem("unitId")
                iscp_port = sessionStorage.getItem("iscp_port") || "";
                let data = {
                    "orgId": orgId,
                    "userId": userId,
                    "timestamp": new Date().getTime(),
                    "pathName": name,
                    "pathValue": val
                };
                data = JSON.stringify(data)
                let sign = sm3(data);
                let resResult
                let AuthenticationSession = sessionStorage.getItem("Authentication");
                var URL
                $.ajax({
                    url: localUrlLink + iscp_port + "/tjAiAssistant/defaultPath/addPath",
                    type: "post",
                    async: false, //是否同步，false表示同步请求
                    dataType: "json",
                    data: data,
                    headers: {
                        "Content-Type": "application/json;charset=UTF-8",
                        Authentication: AuthenticationSession,
                        sign: sign
                    },
                    success: (res, txt, xhr) => {
                        if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                            let Authentication = xhr.getResponseHeader("Authentication")
                            if (res.code == 200) {
                                if (Authentication) {
                                    sessionStorage.setItem("Authentication", Authentication);
                                    mui.toast(res.resultValue, {
                                        duration: 'long',
                                        type: 'div'
                                    })
                                    this.getList()

                                }
                            } else {
                                mui.toast(res.resultValue, {
                                    duration: '1000',
                                    type: 'div'
                                })
                            }
                        } else {
                            mui.toast('完整性校验失败', {
                                duration: '1000',
                                type: 'div'
                            })
                        }
                    },
                    error: (e) => {
                        mui.toast('请求异常,请稍后再试', {
                            duration: '1000',
                            type: 'div'
                        })
                    },
                });
            },
            //    删除和重命名接口
            operaFilePath(name,id) {
                console.log(name,id,"lliyuhang")
                const userId = sessionStorage.getItem("userId");
                iscp_port = sessionStorage.getItem("iscp_port") || "";
                var data = {
                    "userId": userId,
                    "timestamp": new Date().getTime(),
                    "id": name =='2' ? id : this.renameId,

                };
                if (name =='1') {
                    data.pathName = this.inputText
                }
                var URL = (name =='2') ? "/tjAiAssistant/defaultPath/deletePath" : "/tjAiAssistant/defaultPath/renamePathName"
                console.log(URL)
                data = JSON.stringify(data)
                let sign = sm3(data);
                let resResult
                let AuthenticationSession = sessionStorage.getItem("Authentication");
                var URL
                $.ajax({
                    url: localUrlLink + iscp_port + URL,
                    type: "post",
                    async: false, //是否同步，false表示同步请求
                    dataType: "json",
                    data: data,
                    headers: {
                        "Content-Type": "application/json;charset=UTF-8",
                        Authentication: AuthenticationSession,
                        sign: sign
                    },
                    success: (res, txt, xhr) => {
                        if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                            let Authentication = xhr.getResponseHeader("Authentication")
                            if (res.code == 200) {
                                if (Authentication) {
                                    sessionStorage.setItem("Authentication", Authentication);
                                    mui.toast(res.resultValue, {
                                        duration: 'long',
                                        type: 'div'
                                    })
                                    this.getList()

                                }
                            } else {
                                mui.toast(res.resultValue, {
                                    duration: '1000',
                                    type: 'div'
                                })
                            }
                        } else {
                            mui.toast('完整性校验失败', {
                                duration: '1000',
                                type: 'div'
                            })
                        }
                    },
                    error: (e) => {
                        mui.toast('请求异常,请稍后再试', {
                            duration: '1000',
                            type: 'div'
                        })
                    },
                });
            },
            getStringAfterLastColon(str) {
                // 找到最后一个冒号的位置
                const lastColonIndex = str.lastIndexOf(':');
                // 提取最后一个冒号后面的所有字符（不包含冒号本身）
                return str.substring(lastColonIndex + 1);
            },
            // 获取默认路径
            getList() {
                const userId = sessionStorage.getItem("userId");
                const orgId = sessionStorage.getItem("unitId")
                iscp_port = sessionStorage.getItem("iscp_port") || "";
                let data = {
                    "orgId": orgId,
                    "userId": userId,
                    "timestamp": new Date().getTime() + ""
                };
                data = JSON.stringify(data)
                let sign = sm3(data);
                let resResult
                let AuthenticationSession = sessionStorage.getItem("Authentication");
                var URL
                $.ajax({
                    url: localUrlLink + iscp_port + "/tjAiAssistant/defaultPath/searchDefaultPathList",
                    type: "post",
                    async: false, //是否同步，false表示同步请求
                    dataType: "json",
                    data: data,
                    headers: {
                        "Content-Type": "application/json;charset=UTF-8",
                        Authentication: AuthenticationSession,
                        sign: sign
                    },
                    success: (res, txt, xhr) => {
                        console.log(xhr.getResponseHeader("sign"),8989+"sign")

                        if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                            let Authentication = xhr.getResponseHeader("Authentication")
                            if (res.code == 200) {
                                if (Authentication) {
                                    sessionStorage.setItem("Authentication", Authentication);
                                    this.filePathList = res.resultValue;
                                    this.showPopName = false
                                }
                            } else {
                                mui.toast(res.resultValue, {
                                    duration: '1000',
                                    type: 'div'
                                })
                            }
                        } else {
                            mui.toast('完整性校验失败', {
                                duration: '1000',
                                type: 'div'
                            })
                        }
                    },
                    error: (e) => {
                        mui.toast('请求异常,请稍后再试', {
                            duration: '1000',
                            type: 'div'
                        })
                    },
                });
            },

            home() {
                $(location).attr("href", "Home.html");
            },
        },
    });
</script>

</html>